package com.neutech.neusys.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neutech.neusys.service.UserService;
import com.neutech.po.Dept;
import com.neutech.po.User;
import com.neutech.vo.ToAddUserVo;

@RestController
//@CrossOrigin("http://localhost:8081")
@RequestMapping("/neusys/user")
public class UserController {
	@Autowired
	private UserService userService;
//	添加用户
//	@param:user 用户信息
//	@return:添加成功还是失败，"success"/"error"
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public String addNewUser(@RequestParam User user){
		int result = userService.addUser(user);
		if(result==1){
			return "success";
		}else{
			return "error";
		}
	}
//	添加用户界面出现前，要查询信息，填充下拉列表
//	@param:user 用户信息
//	@return:添加成功还是失败，"success"/"error"
	@RequestMapping(value="/toadd")
	public ToAddUserVo toNewUser(){
		return userService.toAddUser();
	}
	/*得到用户id*/
	@RequestMapping(value="/update",method=RequestMethod.GET)
	public String updateUserById(User user){
		System.out.println(user.getId());
		System.out.println(user.getUserName());
		System.out.println(user.getPassword());
		return "sucess";
	}
	/*得到所有用户
	 * @return:用户对象集合
	 * */
	@RequestMapping(value="/queryAllUser",method=RequestMethod.GET)
	public List<User> queryAllUser(){
		
		return userService.queryAllUser();
	}
//	通过接收得id查找相信信息
//	@return:单独用户数据
	@RequestMapping(value="/toupdate",method=RequestMethod.GET)
	public User toupdateUserById(User user){
		return userService.toupdateUserById(user);
	}
//	修改用户信息
//	@return:提示
	@RequestMapping(value="/newUpdate",method=RequestMethod.GET)
	public String updateUser(User user){
		System.out.println(user.getUseType());
		int result = userService.updateUser(user);
		if(result>0){
			return "成功";
		}else{
			return "失败";
		}
	}
}
